// pages/index/welcome.js
const app = getApp()
var util = require('../../utils/util.js')
var http = require('../../utils/server.js')
Page({
  data: {

  },

  onLoad: function (option) {
    console.log(new Date().getTime() + ' 刚进来')
    var that = this;
    const scene = decodeURIComponent(option.scene)
    var admin = scene || null
    that.setData({
      admin: admin
    }) 
    that.getUi()
  },
  getUi: function () {
    var that = this;
    //用户信息
    app.getUserInfo(function (userInfo) {
      if (userInfo != null) {
        that.setData({
          userInfo: userInfo,
          showAuthor: false
        })
        that.getData(userInfo)

      } else {
        that.setData({
          showAuthor: true
        })
      }
    }, that.data.admin)

  },
  onshow: function () {
    this.getUi()
  },
  onParentEvent: function(e) {
    app.loginServer(app.globalData.code, e.detail.encryptedData, e.detail.iv, this.getData, this.data.admin)
  },
  getData: function (userInfo) {
    console.log(new Date().getTime()+' userInfo 返回来了')

    if (userInfo.gangId == '') {
      wx.switchTab({
        url: '/pages/order/myorder/myorder'
      })
    } else {
      wx.switchTab({
        url: '/pages/index/index'
      })
    }
  },
})